#!coding=utf-8
import threading
import time
g_flag = False

def thread_function(flag):
    while not flag:
        print("i am thread function")
        time.sleep(1)
    print("thread function end")

if __name__ == '__main__':
    thread = threading.Thread(target=thread_function, args=(g_flag,))
    thread.start()
    time.sleep(2)
    g_flag = True
    print('main ' + str(threading.get_ident()) + " end")